@extends('shop::layouts.master')
@section('title')
    {{$title}}
@endsection
<style>
    .ordertab{border-top:1px solid #e6e6e6;border-left:1px solid #e6e6e6;font-size: 12px;}
    .ordertab td{border-right:1px solid #e6e6e6;border-bottom:1px solid #e6e6e6;padding: 0px 15px;}
    .orderbg{height:33px;line-height:33px;background:#e6e6e6;border-bottom:1px solid #d5d5d5;text-align:center;}
    .order_top span{color: #1890ff; font-size: 13px}
</style>
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item"></div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label"><span class="x-red">*</span>请选择分类</label>
                    </div>
                    <div class="layui-inline">
                        <select name="maintain_config_pid" lay-filter="maintain_father" lay-verify="required">
                            <option value="">请选择一级分类</option>
                            @foreach($father as $key=>$value)
                            <option value="{{$value['id']}}">{{$value['name']}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="layui-inline">
                        <select name="maintain_config_id" id="maintain_son" lay-filter="maintain_son" lay-verify="required">
                            <option value="">请选择二级分类</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <input type="text" name="custom_title" lay-verify="length" autocomplete="off" placeholder="自定义标题" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label for="L_alias" class="layui-form-label"><span class="x-red">*</span>商品列表</label>
                    </div>
                    <div class="layui-inline">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ordertab">
                            <tr class="orderbg">
                                <td width="500">商品列表</td>
                                <td width="260">选择规格</td>
                                <td width="80">配置数量</td>
                            </tr>
                            @foreach($goods as $ky=>$val)
                                <tr class="goods-list" maintain-pid="{{$val['maintain_pid']}}" maintain-id="{{$val['maintain_id']}}">
                                    <td width="500" style="padding: 15px;">
                                        <img src="{{$val['pic_url']['full_src']}}" style="width: 25px;height: 25px;">
                                        {{$val['name']}}
                                    </td>
                                    <td width="260">
                                        <input type="hidden" name="goods[{{$ky}}][goods_id]" value="{{$val['id']}}">
                                        <div class="layui-input-inline" style="width: 260px">
                                            <select name="goods[{{$ky}}][product_id]" lay-filter="product" class="pro">
                                                <option value="">请选择规格属性</option>
                                                @foreach($val['product'] as $k=>$v)
                                                    <option value="{{$v['id']}}">{{$v['specs']['name']}}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </td>
                                    <td width="80">
                                        <div class="layui-input-inline" style="width: 80px">
                                            <input type="text" name="goods[{{$ky}}][num]" lay-verify="number" value="0" autocomplete="off" class="layui-input goods-num" placeholder="数量">
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                            @if(empty($goods))
                                <td colspan="66" height="40px" align="center">暂无该类商品数据</td>
                            @endif
                        </table>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn layui-btn-normal" lay-filter="add" lay-submit="">提交</button>
                    <input type="hidden" id="stock" value="{{$stock}}">
                </div>
            </form>
        </div>
    </div>

@endsection

@section('tab_js')
    @include('shop::maintain_shop.this_js')
    <script>
        layui.use(['form', 'layer', 'jquery','laydate'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            //监听提交
            form.on('submit(add)', function (data) {
                $.ajax({
                    url: js_url('shop-maintain-shop-store'),
                    type: 'post',
                    data: data.field,
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg(result.msg, {time: 600, icon: 6}, function () {
                                xadmin.close();
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(result.msg, {time: 600, icon: 5});
                        }
                    }
                });
                return false;
            });

        });
    </script>
@endsection




